<?php

class searchsupplier{
public function index(){
$city_id = intval($GLOBALS['request']['city_id']);
$lat = trim($GLOBALS['request']['log']);
$log =trim($GLOBALS['request']['lat']);
$key_word=$GLOBALS['request']['key_word'];
$key_word_unicode = str_to_unicode_string($key_word);
if(empty($key_word)){
$sql= 'SELECT id,name,address,xpoint,ypoint  FROM '.DB_PREFIX."supplier_location    WHERE city_id='{$city_id}' AND deal_type=0   order by avg_point desc ";
}else{
$sql= 'SELECT id,name,address,xpoint,ypoint  FROM '.DB_PREFIX."supplier_location    WHERE match (locate_match,name_match,deal_cate_match)  against('".$key_word_unicode."' IN BOOLEAN MODE) and city_id='{$city_id}'   order by avg_point desc";
}
$list= $GLOBALS['db']->getAll($sql);
foreach($list as $k=>$v)
{
$list[$k]['distance']=get_distion($lat,$log,$v['xpoint'],$v['ypoint']);
unset($list[$k]['preview'],$list[$k]['xpoint'],$list[$k]['ypoint']);
}
foreach($list as $lk=>$lv){
$distance[$lk]=$lv['distance'];
}
array_multisort($distance,SORT_NUMERIC,$list);
$list=array_slice($list,0,10,true);
$root['item']=$list;
output($root);
}
}
?>